<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            height: 100%;
        }

        span {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: skyblue;
            color: pink;
            display: block;
            text-align: center;
            line-height: 50px;
            font-size: 24px;
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>

<body>
    <p>得分：<b>0</b></p>
    <script>
        var spanDom;
        var maxWidth = document.body.clientWidth || document.documentElement.clientWidth;
        var maxHeigh = document.body.clientHeight || document.documentElement.clientHeight;
        var timer;
        var char;
        function getStyle(elem, attr) {
            if (window.getComputedStyle) {
                return window.getComputedStyle(elem)[attr];
            }
            return elem.currentStyle[attr];
        };
        function makeRandom(start,end){
            return Math.floor(Math.random()*(end-start+1)+start);
        }
        function createChar(){
            var arr = 'abcdefghijklmnopqrstuvwxyz123456789';
            var index = makeRandom(0,arr.length-1);
            return arr[index];
        }
        function createSpan(){
            char = createChar();
            spanDom = document.createElement('span');
            spanDom.innerHTML = char;
            var left = makeRandom(0,maxWidth-50);
            spanDom.style.left = left+'px'
            document.body.appendChild(spanDom);
            timer = setInterval(function(){
                var top = parseInt(getStyle(spanDom,'top'));
                if(top>=maxHeigh-50){
                    clearInterval(timer);
                    document.body.removeChild(spanDom);
                    createSpan();
                }else{
                    spanDom.style.top = top + 5 + 'px';
                }
            },200)
        }
        createSpan();
        document.onkeydown = function(e){
            var event = e || window.event;
            if(event.key.toLowerCase() == char){
                clearInterval(timer);
                document.body.removeChild(spanDom);
                createSpan();
                document.querySelector('b').innerHTML = parseInt(document.querySelector('b').innerHTML)+1;
            }
        }
    </script>
</body>

</html>